/* SPDX-License-Identifier: GPL-2.0 */

#ifndef EULEROS_DIM_CORE_MEM_H
#define EULEROS_DIM_CORE_MEM_H

/*
 * single buddy module: 4k * 2^10 = 4MB
 * max memery pool: 4MB * 32 = 128MB
 * init memery pool: 4MB * 4 = 16MB
 * 10W*(256 + 32 + 32 + 32)=3500W=35M
*/
#define DIM_GET_PAGES_ORDER 10
#define DIM_MIN_ALLOC_SIZE 32
#define DIM_MAX_ALLOC_SIZE 9012
#define DIM_MAX_BUDDY_NUMBER 32
#define DIM_INIT_BUDDY_NUMBER 4

/**
 * typedef dim_mem_iterator - iterator function of json memory management modules
 * @pstart: pointer to pre-allocated memory of every module
 * @size: size of pre-allocated memory
 * @data: common data holds during traversing
 *
 * Return: 0 on success or other values on failure
 */
typedef int (*dim_mem_iterator)(void *start, unsigned long size, void *data);

/**
 * dim_mem_init() - init dim memory manager module
 *
 * Returns: 0 on success or errno on failure
 */
int dim_mem_init(void);

/**
 * dim_mem_destroy() - destroy dim memory manager module
 */
void dim_mem_destroy(void);

/**
 * dim_mem_alloc() - alloc memory from dim memory manager module
 * @size: alloc size
 *
 * Returns: pointer to allocated mem block or NULL ob failure
 */
void *dim_mem_alloc(unsigned long size);

/**
 * dim_mem_free() - free memory to dim memory manager module
 * @data: pointer to allocated mem block
 */
void dim_mem_free(void *data);

/**
 * dim_mem_block_traverse() - traverse every dim memory block
 * @f: iterator function
 * @data: common data holds during traversing
 *
 * Return: 0 on success or other values on failure
 */
int dim_mem_block_traverse(dim_mem_iterator f, void *data);

/**
 * dim_mem_get_block_counts() - get number of memory blocks
 *
 * Return: number of memory blocks
 */
unsigned long dim_mem_get_block_counts(void);

#endif /* EULEROS_DIM_CORE_MEM_H */
